package com.leyou.item.controller;

import com.leyou.dto.pojo.SpecGroupDTO;
import com.leyou.dto.pojo.SpecParamDTO;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HeGuanChao
 * @Description TODO 规格controller
 * @Date 2020/4/1 11:10
 */
@RestController
@RequestMapping("/spec")
public class SpecController {
    @Autowired
    private SpecService specService;

    /**
     * 查询规格组
     *
     * @param id 分类id
     * @return 规格组列表
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecGroupByCid(@RequestParam("id") Long id) {
        return ResponseEntity.ok(specService.querySpecGroupByCid(id));
    }

    /**
     * 查询规格参数
     * @param gid 规格组id
     * @param cid 分类id
     * @param searching 搜索条件
     * @return 规格参数列表
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParamByGid(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching) {
        return ResponseEntity.ok(specService.querySpecParamByGid(gid,cid,searching));
    }

    /**
     * 根据分类id查询规格组和规格参数
     * @param id 分类id
     * @return 规格组和规格参数
     */
    @GetMapping("/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsByCid(@RequestParam("id") Long id){
        return ResponseEntity.ok(specService.querySpecsByCid(id));
    }
}
